<%--
  Created by IntelliJ IDEA.
  User: zyh
  Date: 2021/10/29
  Time: 14:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form action="${ctx}/emp?method=login" method="post" >
        账号<input type="text" name="username"></br>
        密码<input type="password" name="pwd"></br>
        <img id="vimg" src="${ctx}/code" alt=""></br>
        <input type="text" name="code" id="code"><span id="msg"></span></br>
        <input type="submit" id="sub" disabled><span>${msg}</span>
    </form>
    <script>
        $(function () {
           $("#code").change(function () {
                var code = $(this).val();
                $.get("${ctx}/emp?method=checkCode&code="+code,function(data) {
                    var msg = JSON.parse(data);
                    //获取到msg里存储的result数据
                    if (msg.result) {
                        $("#msg").text("正确了").css("color", "green");
                        //disabled，设置不可用false
                        $("#sub").prop("disabled", false);
                    }else {
                        $("#msg").text("错误了").css("color","red");
                        $("#sub").prop("disabled",true);
                    }
                });
            });
                $('#vimg').click(function () {
                    $('#vimg').attr("src","${ctx}/code?name="+Math.random());
                })
        })
    </script>
</body>
</html>
